<?php
namespace Home\Controller;
use Think\Controller;
use Home\Model\UserModel;
class LoginController extends Controller {
    public function index(){
    $this->display('login');
}
  public function verify(){
      $verify=new \Think\Verify();
      $verify->entry(1);
  }
  
   //登录验证  
    public function checkLogin(){
        if(IS_AJAX){
           $userModel=new UserModel();
            $uid= $userModel->login($_POST['log_user'],$_POST['log_password']);
            $jsonResult=array();
            if($uid > 0 ){
                  $jsonResult["flag"] = true;  
                }else{
                  $jsonResult["flag"] = false; 
                }
                echo json_encode($jsonResult);
            }else{
            $this->error('非法访问');
            }
    } 
    
   
    //登录 管理
   public function checkRegister(){
        if(IS_AJAX){
           $userModel=new UserModel();
            $uid= $userModel->register($_POST['user'],$_POST['password'],$_POST['repassword'],$_POST['email'],$_POST['verify']);
                $jsonResult=array();
            if(!empty($uid) ){
                  $jsonResult["flag"] = true;  
                }else{
                   $jsonResult["flag"] = false; 
                }
                echo json_encode($jsonResult);
            }else{
            $this->error('非法访问');
            }
    }
  //验证用户名是否存在  
    public function checkUser(){
        if(IS_AJAX){
           $userModel=new UserModel(); 
           $uid=$userModel->checkField($_POST['user'], 'user');
           echo  $uid >0 ? 'true' : 'false';
        }
    }
 //验证电子邮件是否存在   
    public function checkEmail(){
        if(IS_AJAX){
           $userModel=new UserModel(); 
           $uid=$userModel->checkField($_POST['email'], 'email');
           echo  $uid >0 ? 'true' : 'false';
        }
    }
    
     //验证码验证  
    public function checkVerify(){
        if(IS_AJAX){
           $userModel=new UserModel(); 
           $uid=$userModel->checkField($_POST['verify'], 'verify');
           echo  $uid >0 ? 'true' : 'false';
        }
    }
    
    //退出登录
    public function logout(){
        session_destroy();  //清除服务器的sesion文件
        $this->redirect('Login/index');
    }

}
?>